
export class DateUtils {

    /**
     * 返回星期几
     * @param time 日期
     * @returns 
     */
    static weekDay(time: string) {
        const weekNum = new Date(time).getDay();
        const week = {
            0: "星期天",
            1: "星期一",
            2: "星期二",
            3: "星期三",
            4: "星期四",
            5: "星期五",
            6: "星期六"
        } as any
        return week[weekNum] ? week[weekNum] : "日期错误";
    }

    /**
    * 日期路径 即年/月/日 如2018/08/08
    */
    static detePath() {
        const TheDate = new Date();
        return TheDate.getFullYear() + "/" + (TheDate.getMonth() + 1).toString().padStart(2, "0") + "/" + TheDate.getDate().toString().padStart(2, "0");
    }

    static dateTimeNow() {
        const TheDate = new Date();
        return TheDate.getFullYear() + (TheDate.getMonth() + 1).toString().padStart(2, "0") + TheDate.getDate().toString().padStart(2, "0") + TheDate.getHours().toString().padStart(2, "0") + TheDate.getMinutes().toString().padStart(2, "0") + TheDate.getSeconds().toString().padStart(2, "0") + TheDate.getMilliseconds();
    }

    /**
     * 格式化对应日期
     * @param date 日期
     * @returns yyyy-mm-dd
     */
    static getComDate(date: string) {
        const TheDate = new Date(date);
        return TheDate.getFullYear() + "-" + (TheDate.getMonth() + 1).toString().padStart(2, "0") + "-" + TheDate.getDate().toString().padStart(2, "0");
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd
     */
    static getNowComDate() {
        const TheDate = new Date();
        return TheDate.getFullYear() + "-" + (TheDate.getMonth() + 1).toString().padStart(2, "0") + "-" + TheDate.getDate().toString().padStart(2, "0");
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd hh:ii:ss
     */
    static getNowFullDateJSON() {
        const TheDate = new Date();
        return TheDate.getFullYear() + "-" + (TheDate.getMonth() + 1).toString().padStart(2, "0") + "-" + TheDate.getDate().toString().padStart(2, "0") + " " + TheDate.getHours().toString().padStart(2, "0") + "时" + TheDate.getMinutes().toString().padStart(2, "0") + "分" + TheDate.getSeconds().toString().padStart(2, "0") + "秒 " + TheDate.getMilliseconds() + "毫秒";
    }

    /**
     * 获取今天格式化日期
     * @returns yyyy-mm-dd hh:ii:ss
     */
    static getNowFullDate() {
        const TheDate = new Date();
        return TheDate.getFullYear() + "-" + (TheDate.getMonth() + 1).toString().padStart(2, "0") + "-" + TheDate.getDate().toString().padStart(2, "0") + " " + TheDate.getHours().toString().padStart(2, "0") + ":" + TheDate.getMinutes().toString().padStart(2, "0") + ":" + TheDate.getSeconds().toString().padStart(2, "0") + " " + TheDate.getMilliseconds();
    }

    /**
     * 获取当前时间
     * @returns new Date()
     */
    static getNowDate() {
        return new Date();
    }

    /**
     * 获取上传文件日期文件名
     * @returns 
     */
    static getDateFile(){
        const TheDate = new Date();
        return TheDate.getFullYear() +"\\"+ (TheDate.getMonth() + 1).toString().padStart(2, "0") +"\\"+ TheDate.getDate().toString().padStart(2, "0") +"\\"+ TheDate.getHours().toString().padStart(2, "0")
    }
}